{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <br>
    <div class="layui-anim layui-anim-up">
        <form class="layui-form">
            <input type="hidden" name="id" value="{{$info['id']}}">
            <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属用户组</label>
                        <div class="layui-input-inline">
                            <select name="group_id" lay-verify="required">
                                @foreach($group as $vo)
                                <option value="{{$vo->group_id}}" {{($info['group_id'] == $vo->group_id)? "selected":""}}>{{$vo->title}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="username" autocomplete="off" placeholder="请输入用户名" class="layui-input" lay-verify="required" value="{{$info['username']}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <input type="hidden" name="avatar" id="avatar" value="{{$info['avatar']}}">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn layui-btn-black" id="adBtn"><i class="layui-icon" style="color: #fff">&#xe67c;</i>点击上传</button>
                                <div class="layui-upload-list">
                                    @if($info['avatar'] != '')
                                        <img class="layui-upload-img" id="adPic" width="80" height="80" src="{{$info['avatar']}}" style="border-radius: 50%;">
                                    @else
                                        <img class="layui-upload-img" id="adPic" width="80" height="80" src="{{asset('admin/images/head.jpg')}}" style="border-radius: 50%;">
                                    @endif
                                    <p id="demoText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="display: none;" id="jin">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-inline">
                            <div class="layui-progress" lay-showPercent="yes" lay-filter="progressBar">
                                <div class="layui-progress-bar layui-btn-blue" lay-percent="0%"></div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn layui-btn-black" lay-submit="" lay-filter="edit">编辑</button>
                            <button type="reset" class="layui-btn  layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script>
        layui.use(['form','layer','upload','element'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,upload = layui.upload
                ,element = layui.element
                ,$ = layui.jquery;

            var _token =  $('meta[name="csrf-token"]').attr('content');

            //监听提交
            form.on('submit(edit)', function(data){
                data.field._token = _token;
                $.post("{{url('admin/auth/adminedit')}}",data.field,function(res){
                    if(res.code == 1){
                        layer.msg(res.msg,function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
            });
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#adBtn'
                ,url: "{{url('admin/upfiles/upimages')}}"
                ,data:{_token:_token,files:'admins'}
                ,progress: function(e , percent) {
                    $("#jin").show();
                    element.progress('progressBar',percent  + '%');
                }
                ,done: function(res){
                    if(res.code>0){
                        $('#adPic').show();
                        $('#adPic').attr('src', '/uploads/'+res.src);
                        $("#adPic").css({"width":80+"px","height":80+"px"});
                        $('#avatar').val('/uploads/'+res.src);
                        layer.msg(res.msg);
                    }else{
                        //如果上传失败
                        $("#jin").hide();
                        layer.msg('上传失败');
                        return false;
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    $("#jin").hide();
                    layer.msg('上传失败');
                    return false;
                }
            });
        });
    </script>
@endsection